<template>
  <div>
    <ul>
        <li v-for="message in messageList" :key="message.id">
            <!-- 路由跳转并携带params参数 - to的字符串写法 -->
            <!-- params参数写法直接/后加数据，在index.js下配置数据名 -->
            <!-- <router-link :to="`/home/message/detail/${message.id}/${message.title}`">{{message.title}}</router-link> -->
            <!-- 路由跳转并携带params参数 - to的对象写法 -->
            <router-link :to="{
                // path:'/home/message/detail',//使用params参数进行传值时，必须使用name来传递路径。
                //name写法
                name:'detail',
                query:{
                    id:message.id,
                    title:message.title
                }
            }"> 
            {{message.title}}
            </router-link>
            <!-- 编程式路由导航 -->
            <button @click="pushShow(message)">PUSH查看</button>
            <button @click="replaceShow(message)">REPLACE查看</button>
        </li>
    </ul>
    <router-view></router-view>
  </div>
</template>

<script>
export default {
    name:'Message',
    data() {
        return {
            messageList:[
                {id:'001',title:"消息1"},
                {id:'002',title:'消息2'},
                {id:'003',title:'消息3'}
            ]
        }
    },
    methods:{
        pushShow(message){
            this.$router.push({
                name:"detail",
                query:{
                    id:message.id,
                    title:message.title
                }
            })
        },
        replaceShow(message){
            this.$router.replace({
                name:'detail',
                query:{
                    id:message.id,
                    title:message.title
                }
            })
        }
    }
}
</script>

<style scoped>
    button{
        margin-left:10px;
    }
</style>